import request from '@/utils/request'
import type { PatientList, User, UserInfo } from '@/types/user'
/**
 * 通过密码登录
 * @param loginData {mobile: string, password: string}
 * @returns {User}
 */
export const loginService = (loginData: any) => {
  return request.post<User>('/login/password', loginData)
}

/**
 * 手机验证码登录（模拟）
 * @param loginData {mobile: string, code: string}
 * @returns
 */
export const loginByCodeService = (loginData: any) => {
  return request.post<User>('/login', loginData)
}

/**
 * 获取验证码
 * @param mobile 手机号
 * @param type 验证码类型
 * @returns
 */
export const getCodeService = (mobile: string, type: string) => {
  return request.get<{ code: string }>(`/code?mobile=${mobile}&type=${type}`)
}

/* 注册 */
export const registerService = (data: { mobile: string; code: string; password: string }) => {
  return request.post<{ id: string }>('/register', data)
}

/**
 * 获取个人用户信息
 * @returns
 */
export const getUserInfoService = () => {
  return request.get<UserInfo>('/patient/myUser')
}

/**
 * 退出登录
 * @returns
 */
export const logoutService = () => {
  return request.get('/logout')
}

/**
 * 获取患者信息列表
 * @returns
 */
export const getPatientListService = () => {
  return request.get<PatientList>('/patient/mylist')
}

/**
 * 新增患者
 * @param patientData
 * @returns
 */
export const addPatientService = (patientData: any) => {
  return request.post('/patient/add', patientData)
}

/**
 * 编辑患者
 * @param patientData
 * @returns
 */
export const updatePatientService = (patientData: any) => {
  return request.put('/patient/update', patientData)
}

/**
 * 删除患者
 * @param id 患者id
 * @returns
 */
export const deletePatientService = (id: string) => {
  return request.delete(`/patient/del/${id}`)
}
